package cn.dengta.webapp.im.dto;

import java.util.*;
import java.util.stream.Collectors;

import cn.dengta.context.model.WesKit;
import cn.dengta.webapp.model.UpgradeAward;
import cn.dengta.webapp.model.UpgradeBall;
import lombok.Getter;
import lombok.Setter;
import me.codeplayer.util.X;

/**
 * 聊天相关配置
 */
@Getter
@Setter
public class MsgConfigDTO {

	/** 升温球奖励配置 */
	private Map<WesKit, List<BallAward>> ballAwards;

	public static MsgConfigDTO findDef() {
		return new MsgConfigDTO();
	}

	public Map<WesKit, List<BallAward>> getBallAwards() {
		if (ballAwards == null) {
			ballAwards = new HashMap<>();
			for (WesKit wesKit : WesKit.CACHE) {
				List<BallAward> awards = new ArrayList<>();
				boolean isHolaMet = false;
				awards.add(new BallAward().init(1, UpgradeBall.GIFT, 200, 7, UpgradeAward.BUBBLE)
						.buildIcon(isHolaMet ? UpgradeAward.BUBBLE.getIcon() : null));
				awards.add(new BallAward().init(2, UpgradeBall.GIFT, 2000, -1, UpgradeAward.BUBBLE)
						.buildIcon(isHolaMet ? UpgradeAward.BUBBLE.getIcon() : null));
				awards.add(new BallAward().init(10, UpgradeBall.CALL, 200, 7, UpgradeAward.BACKDROP)
						.buildIcon(isHolaMet ? UpgradeAward.BACKDROP.getIcon() : null));
				awards.add(new BallAward().init(11, UpgradeBall.CALL, 2000, -1, UpgradeAward.BACKDROP)
						.buildIcon(isHolaMet ? UpgradeAward.BACKDROP.getIcon() : null));
				ballAwards.put(wesKit, awards);
			}
		}
		return ballAwards;
	}

	public List<BallAward> findBallAwardOrDef(WesKit wesKit, UpgradeBall ball) {
		List<BallAward> awardList = getBallAwards().get(wesKit);
		return X.isValid(awardList) ? awardList.stream().filter(a -> a.ball == ball).collect(Collectors.toList()) : Collections.emptyList();
	}

	/**
	 * 升温球奖励配置
	 */
	@Getter
	@Setter
	public static class BallAward {

		/** 升级包类型 */
		public UpgradeBall ball;
		/** 所需的砖石数 */
		public Integer minCoin;
		/** -1代表永久， 正数代表天 */
		public Integer amount;
		/** 奖励类型 */
		public UpgradeAward award;
		/** 图标 */
		public String icon;
		/** 唯一标记，不能重复不能更改 */
		public Integer index;

		public BallAward init(Integer index, UpgradeBall ball, Integer minCoin, Integer amount, UpgradeAward award) {
			this.index = index;
			this.ball = ball;
			this.minCoin = minCoin;
			this.amount = amount;
			this.award = award;
			return this;
		}

		public BallAward buildIcon(String icon) {
			this.icon = icon;
			return this;
		}

	}

}
